package com.sheliduan.itlearning.common.domain.mapper;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sheliduan.itlearning.common.domain.dos.ArticleCategoryRelDO;
import com.sheliduan.itlearning.common.domain.dos.ArticleTagRelDO;

/**
 * @author: 断舍离
 * @date: 2025/2/10 10:07
 * @description: 文章课程_分类关联映射接口
 **/
public interface ArticleCategoryRelMapper extends BaseMapper<ArticleCategoryRelDO> {

    /*
    * 删除该articleId_分类的所有关联数据
    * */
    default int deleteRelByArticleId(Integer articleId){
        LambdaUpdateWrapper<ArticleCategoryRelDO> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(ArticleCategoryRelDO::getArticleId, articleId);
        return delete(wrapper);
    }

    /*
     * 修改改文章对应的分类
     * */
    default int updateRelByArticleId(Integer articleId, Integer categoryId) {
        LambdaUpdateWrapper<ArticleCategoryRelDO> wrapper = new LambdaUpdateWrapper<>();
        wrapper.set(ArticleCategoryRelDO::getCategoryId, categoryId);
        wrapper.eq(ArticleCategoryRelDO::getArticleId, articleId);
        return update(null, wrapper);
    }
}
